package testcase.doctor;


import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import api.doctor.ExistHtml;
import common.Host;
import common.TestData;

/**
 * 帮忙医医生端退出登录接口ExistHtml测试用例
 * @author gaowen
 *
 */
public class TestExistHtml
{
	/**
	 * 帮忙医医生端退出登录接口ExistHtml测试环境数据驱动
	 * @return 测试数据
	 * @throws Exception 
	 */
	@DataProvider(name="Test")
	public static String[][] testExistHtmlDataProvider() throws Exception
	{
		Host.setup("Test");
		TestData tData=new TestData("doctor/TestExistHtml.xml");
		return tData.getParam();
	}
	
	/**
	 * 帮忙医医生端退出登录接口ExistHtml测试环境测试用例
	 * @param caseName 用例名
	 * @param Id 医生ID
	 * @param token 调接口需要的token
	 * @throws Exception
	 */
	@Test(dataProvider="Test",groups="Test")
	public void testExistHtmlTestCase(String caseName,String Id,String token) throws Exception
	{
		String result=ExistHtml.post(Id, token);
		
		JSONObject jsonResult;
		if (result==null||result.isEmpty())
		{
			jsonResult=null;
		}
		else
		{
			jsonResult=new JSONObject(result);
		}
		
		switch (caseName)
		{
			case "Success":
				if (jsonResult.getJSONObject("Data").getInt("Count")!=0)
				{
					Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("Free"));
				}
				else 
				{
					Assert.assertTrue(jsonResult.getJSONObject("Data").getBoolean("Free"));
				}
				break;
			case "IdWrong":
				Assert.assertNull(result);
				break;
			case "IdNull":
				Assert.assertNull(result);
				break;
			case "TokenWrong":
				Assert.assertNull(result);
				break;
			case "TokenNull":
				Assert.assertNull(result);
				break;
			default:
				break;
		}
	}
}
